package org.sxdata.jingwei.util.CommonUtil;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * Created by admin on 2019/3/20.
 */
public class SpringBeanHandler implements ApplicationContextAware {

    public static Object getBean(String name){
        if(applicationContext==null){
            System.err.println("ApplicationContext is null!");
        }
        return applicationContext.getBean(name);
    }
    public static Object getBean(Class clsName){
        if(applicationContext==null){
            System.err.println("ApplicationContext is null!");
        }
        return applicationContext.getBean(clsName);
    }
    private static ApplicationContext applicationContext;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {

        this.applicationContext = applicationContext;
    }
}
